import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

//1、AnimatedOpacity（实现渐变效果）

//void main(){
//  runApp(new MyHomePage());
//}


class MyHomePage extends StatefulWidget{

//  final String title;
//  MyHomePage({Key key, this.title}) : super(key : key);


  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new MyHomePageState();
  }

}

class MyHomePageState extends State<MyHomePage>{

  final appTitle = "淡入淡出动画示例";
  //控制动画显示状态变量
  bool _visible = true;

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: appTitle,
      home: new Scaffold(
        appBar: AppBar(
          title: Text(appTitle),
          centerTitle: true,
        ),
        body: new Center(
          //添加 Opacity动画
          child: new AnimatedOpacity(
              //控制opacity 值范围从 0.0 到 1.0
              opacity: _visible ? 1.0 : 0.0,
              // 设置动画时长
              duration: new Duration(
                milliseconds: 1000,
              ),
              child: new Container(
                width: 300.0,
                height: 300.0,
                color: Colors.deepPurple,
              ),
          ),
        ),
        floatingActionButton: new FloatingActionButton(
            onPressed: (){
              //控制动画显示状态
              setState(() {
                _visible = !_visible;
              });
            },
            tooltip: "显示隐藏",
            child: new Icon(Icons.flip),
        ),
      ),
    );
  }

}

//2、Hero（页面切换动画）

void main(){
  runApp(new MaterialApp(
    title: "",
    home: new FirstPage(),
  ));
}

class FirstPage extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: AppBar(
        title: Text("Hero（页面切换动画）"),
        centerTitle: true,
      ),
      body: new GestureDetector(
        child: new Hero(
          tag: "第一张照片",
          child: new Image.asset("images/timg.jpg"),
        ),
        onTap: (){
          Navigator.push(
              context,
              new MaterialPageRoute(builder: (_){
                return new SecondPage();
              }));
        },
      ),
    );
  }

}

class SecondPage extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return  new Scaffold(
      appBar: AppBar(
        title: Text("Hero（页面切换动画）"),
        centerTitle: true,
      ),
      body: new GestureDetector(
        child: new Hero(
          tag: "第二张照片",
          child: new Image.asset("images/image9.jpg"),
        ),
        onTap: (){
          Navigator.pop(context);
        },
      ),
    );
  }

}





